<?php
	class TTSK
	{
		var $mattsk;
		var $tieude;
		var $anhbia;
		var $noidung;
		var $capdo;
		var $ngaydang;
		var $theloai;
		var $nguoidang;// người viết bài 
		var $tennguoidang;
		function __construct($ma,$mahvdang,$tl,$td,$ab,$nd,$cd,$ngay,$ten)
		{
			$this->mattsk=$ma;
			$this->nguoidang=$mahvdang;
			$this->theloai=$tl;
			$this->tieude=$td;
			$this->anhbia=$ab;
			$this->noidung=$nd;
			$this->capdo=$cd;
			$this->ngaydang=$ngay;
			$this->tennguoidang=$ten;
		}
		 public static function  GetTinTucSuKienTheoTL($sotin,$tl,$capdo)
		{
			include("handle/config.php");
			$ttsk=array();
			// lấy danh sách tin tức sự kiên
			$sql = "SELECT * FROM TINTUC_SUKIEN, THELOAITTSK, HOIVIEN 
					 WHERE HOIVIEN.MAHV=TINTUC_SUKIEN.MAHV 
			 		AND   TINTUC_SUKIEN.MATL=THELOAITTSK.MATL 
					AND THELOAITTSK.TENTL='$tl' 
					AND CAPDOTTSK='$capdo'
					ORDER BY NGAYDANGTTSK DESC LIMIT $sotin";
			$result=mysqli_query($con,$sql);
			$i=0;
			while($row=mysqli_fetch_array($result))
			{
				
				$ttsk[$i]=new TTSK($row['MATT'],$row['MAHV'],$row['MATL'],$row['TIEUDE'],$row['ANHBIA'],$row['NOIDUNGTTSK'],$row['CAPDOTTSK'], $row['NGAYDANGTTSK'],$row['HOTEN']);
				$i++;
			}
			return $ttsk;
		}
		public static function  GetTinTucSuKienTheoMa($matt)
		{
			include("handle/config.php");
			
			$sql = "SELECT * FROM TINTUC_SUKIEN, HOIVIEN 
				WHERE HOIVIEN.MAHV=TINTUC_SUKIEN.MAHV 
				AND TINTUC_SUKIEN.MATT='$matt'";
			$result=mysqli_query($con,$sql);
			while($row=mysqli_fetch_array($result))
			{
				$ttsk=new TTSK($row['MATT'],$row['MAHV'],$row['MATL'],$row['TIEUDE'],$row['ANHBIA'],$row['NOIDUNGTTSK'],$row['CAPDOTTSK'],$row['NGAYDANGTTSK'],$row['HOTEN']);
			}
			return $ttsk;
		}
		public static function  GetTinTucSuKienTheoCH($matl,$sotin)
		{
			include("handle/config.php");
			// lấy danh sách hoạt động ra theo điều kiện được yêu cầu
			
			$sql = "SELECT * FROM TINTUC_SUKIEN, HOIVIEN
						WHERE TINTUC_SUKIEN.MAHV=HOIVIEN.MAHV 
						AND HOIVIEN.MACH='$_SESSION[matructhuoc]'
						AND  TINTUC_SUKIEN.MATL='$matl'
						AND  TINTUC_SUKIEN.CAPDOTTSK='Chi Hội'
						ORDER BY NGAYDANGTTSK DESC LIMIT $sotin";
			$result=mysqli_query($con,$sql);
			$i=0;
			while($row=mysqli_fetch_array($result))
			{
				
				$ttsk[$i]=new TTSK($row['MATT'],$row['MAHV'],$row['MATL'],$row['TIEUDE'],$row['ANHBIA'],substr($row['NOIDUNGTTSK'],0,300),$row['CAPDOTTSK'],$row['NGAYDANGTTSK'],$row['HOTEN']);
				$i++;
			}
			return $ttsk;
		}
		public static function GetTinTucSuKien($sotin,$capdo)
		{
			$ttsk=array();
			 include("handle/config.php");
			
			$sql = "SELECT * FROM TINTUC_SUKIEN, HOIVIEN WHERE HOIVIEN.MAHV=TINTUC_SUKIEN.MAHV AND CAPDOTTSK='$capdo' ORDER BY NGAYDANGTTSK DESC LIMIT $sotin";
			$result=mysqli_query($con,$sql);
			$i=0;
			while($row=mysqli_fetch_array($result))
			{
				
				$ttsk[$i]=new TTSK($row['MATT'],$row['MAHV'],$row['MATL'],$row['TIEUDE'],$row['ANHBIA'],substr($row['NOIDUNGTTSK'],0,300),$row['CAPDOTTSK'],$row['NGAYDANGTTSK'],$row['HOTEN']);
				$i++;
			}

			return $ttsk;
		}
	}

?>